package game.ability;

import java.util.Random;

import game.entity.AbsSprite;
import game.shared.Constants;

public class MovingSnowDown  extends AbsMoving {

	Random random;
	int nDoiChieu;
	boolean bChieu;
	float giatoc;
	int n;
	
	@Override
	public void run(AbsSprite sprite) {
		n++;
		float x = sprite.getX();
		float y = sprite.getY();
		if(n>nDoiChieu)
			Setting();
		
		float v = speed * giatoc;
		if(bChieu)
			x += v;
		else
			x -= v;
		y -= v/(1.2 + random.nextInt(10)/10);
		
		if(y<0)
			y = Constants.SCREEN_HEIGHT + random.nextInt(20);
		if(x<0 || x>Constants.SCREEN_WIDTH)
			x = 10 + random.nextInt(300);
		
		sprite.setPosition(x, y);
	}
	
	private void Setting()
	{
		random = new Random();
		nDoiChieu = 15 + random.nextInt(15);
		bChieu = random.nextBoolean();
		giatoc = 0.7f + (random.nextInt(50)/100f);
		n=0;
	}
	
	public MovingSnowDown(float speed)
	{
		super(speed/10f);
		Setting();
	}
}
